import Mock from 'mockjs'

export default function mockCommon(app) {
  // 模拟登录接口
  app.post('/api/login', (req, res) => {
    const { username, password } = req.body
    if (username === 'admin' && password === '123456') {
      res.json({
        success: true,
        message: '登录成功！',
        data: { token: 'mock-token' },
      })
    } else {
      res.status(401).json({
        success: false,
        message: '用户名或密码错误！',
      })
    }
  })

  // 模拟数据接口
  app.get('/api/data', (req, res) => {
    res.json({
      success: true,
      data: Mock.mock({
        'list|5': ['@id'],
      }),
    })
  })
}